<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/2 11:19
 * Modified Time: 2019/7/2 11:19
 * Version: 2.0
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Goods extends Model
{
    use SoftDeletes;

    protected $table = 'goods';

    protected $fillable = [
        'store_id',
        'cat_id',
        'name',
        'small_name',
        'buying_price',
        'market_price',
        'royalty',
        'is_sell',
        'specs',
        'volume',
        'status',
        'image'
    ];

    public function picture(){
        return $this->hasOne(Picture::class,'id','image');
    }

	public function image(){
		return $this->hasOne(Picture::class,'id','image');
	}

    public function goodsCategory()
    {
        return $this->hasOne(GoodsCategory::class,'id','cat_id');
    }

    public function goodsOrder()
    {
        return $this->hasMany(GoodsOrder::class,'goods_id','id');
    }

    public function goodsStock()
    {
        return $this->hasOne(GoodsStock::class,'goods_id','id');
    }

    public function store(){
        return $this->belongsTo(Store::class,'store_id','id');
    }


    public static function getGoodsInfoById($goodsId){
    	return self::where(['id'=>$goodsId])->select(['id','name'])->first();
    }
}